package com.qf.controller;

import com.qf.entity.TUser;
import com.qf.mapper.TUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author LiuLiang
 * @Date 2020/3/12
 */
@Controller
@RequestMapping("/back")
public class LoginController {
    @Autowired
    private TUserMapper userMapper;

    @Autowired
    private BCryptPasswordEncoder encoder;

    @RequestMapping("/checkLogin")
    @ResponseBody
    public TUser checkLogin(String username, String password){
        TUser tempUser = new TUser();
        tempUser.setUname(username);
        TUser tUser = userMapper.selectOne(tempUser);

        if (tUser!=null){
            System.out.println(tUser);
            if (encoder.matches(password,tUser.getPassword())){

                return tUser;
            }
        }
        System.out.println(password);
        System.out.println(encoder.matches("aaa",tUser.getPassword()));
        return null;
    }
}
